<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@include file="/common/common.jspf" %>
<script type="text/javascript" src="${ctx}/js/order/order_chai.js"></script>
<style type="text/css">
.col-sm-3 {
	width: 15%;
	float: left;
}

.col-sm-9 {
	width: 85%;
	float: left;
}
label[class^="btn btn-default"]{
	margin-top: -4px;
}
</style>
</head>
<body>
	<div class="l_err" style="width: 100%; margin-top: 2px;"></div>
	<form id="form" name="form" class="form-horizontal" method="post"
		action="${ctx}/order/order_chaiEntity.shtml">
		<input type="hidden" class="form-control checkacc" value="${order.id}"
			name="orderFormMap.id" id="id">
		<section class="panel panel-default">
			<div class="panel-body">
				<div class="form-group">
					<label class="col-sm-3 control-label">总数量:</label>
					<div class="col-sm-9">${order.number }</div>
				</div>
			</div>
			<div class="panel-body">
				<div class="form-group">
					<label class="col-sm-3 control-label">订单复制模号</label>
					<div class="col-sm-9">
					<c:if test="${!empty copyMold}">
						<c:forEach var="mold" items="${copyMold }"> 
							${mold.mold_code }
						</c:forEach>
						,
					</c:if>
					<c:if test="${empty orderchai}">
						无
					</c:if>
					</div>
				</div>
			</div>
			<div class="panel-body">
					<div class="form-group">
					<label class="col-sm-3 control-label">拆分数量:</label>
					<div class="col-sm-9" id="chai">
						订单剩余数量:
						<input type="text" class="form-control" id="residue" name="residue" readonly value="${order.number}"/>
					</div>
					<label class="col-sm-3 control-label"></label>
					<div class="col-sm-9" id="chai">
						<button type="button" id="againChai" class="btn btn-info marR9">拆</button>
					</div>
					</div>
			</div>
			<label class="col-sm-3 control-label"></label>
					<div class="col-sm-9" id="chai">
						<button type="submit" class="btn btn-success btn-s-xs">提交</button>
					</div>
		</section>
	</form>
	<script type="text/javascript">
		$(function(){
			var i=1;
			$("#againChai").click(function() {
				var residue=$("#residue").val();
				var reg=/^\+?[1-9][0-9]*$/;
				if(reg.test(residue)==false){
					alert("请输入数字");
					$(".chainumber:last").focus().val('');
					return;
				}
				if(i!=1){
					if($(".chainumber:last").val()==null||$(".chainumber:last").val()==''){
						return;
					}
				}  
				var lastval=$(".chainumber:last").val();
				if(typeof(lastval)=="undefined"){
					lastval=0;
				}
				var residue=$("#residue").val();
				if(residue-lastval<0){
					alert("数量不足!");
					$(".chainumber:last").focus().val('');
					return;
				}
				$("#residue").val(residue-lastval);
				$(".chainumber:last").attr("readonly",true);
				var html="第"+i+"次拆分数量:<input type='text' class='form-control chainumber' name='chainumber' required/>";
				
				$("#chai").append(html);
				$(this).val("确定");
				i++;
			});
		});
	</script>
</body>
</html>